var minimumTimeBetweenClicks = 5000;
var minimumClickTimeForError = 1000;
var allowClick = true;

function LaunchGame(ip, port, playername, playerid){
	if(allowClick){
		var applet = document.gameLaunchApplet;
		var string = applet.AttemptLaunch(ip, port, playername, playerid);
		
		var errorSplit = string.split("#");
		var successSplit = string.split("|");
		
		if(errorSplit.length > 1){ //If an error occured
			Alert("An error occured: " + errorSplit[1]);
			DisableClick();
			setTimeout(EnableClick, minimumClickTimeForError);	
		}
		else{ //No error occured, the game should be launced. Wait a while until the executable can be started again.
			DisableClick();
			setTimeout(EnableClick, minimumTimeBetweenClicks);	
		}
	}
}
function DisableClick(){
	allowClick = false;
}
function EnableClick(){
	allowClick = true;
}